<?php

namespace App\Http\Controllers\Bind;

use App\Helpers\ResponseData;
use App\Http\Controllers\Controller;
use App\Models\Divide\PdProduct;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class BindProductController extends Controller
{
    //
    use ResponseData;
    public function batchCreate(PdProduct $model,Request $request){
        if(is_array($request->products)){
            $arr = $request->products;
        }else{
            $arr = json_decode($request->products,true);
        }
        foreach ($arr as $key=>$item){
            $data[$key]['product_id'] = $item['productId'];
            $data[$key]['product_name'] = $item['productName'];
            $data[$key]['product_shop'] = $item['productShop'];
            $data[$key]['level_value'] = $item['levelValue'];
            $data[$key]['account_mode'] = $item['accountMode'];
            $data[$key]['product_shop_id'] = $item['productShopId'];
            $data[$key]['account_mode'] = $item['accountMode'];
            $data[$key]['product_img'] = $item['productImg'];
            $data[$key]['money'] = $item['money'];
        }
        if($data){
            DB::table('pd_product')->insert($data);
        }
        return $this->success('更新成功');
    }
}
